<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="author" content="hexinyang">
<title>升级不记名卡</title>
<script language="javascript" type="text/javascript"
	src="../script/print.js"></script>
<script language="javascript" src="../script/common.js"
	type="text/javascript"></script>
<script language="javascript" src="../script/card.js"
	type="text/javascript"></script>
<script language="javascript" type="text/javascript">	
	var pageData = {
		cardUser : null,
		cardPin : null
	}
	function load(){
		Eui.showNavigation();
		setPages(["readcardview","detview"]);
		CardMgnt.customer.show("customerdiv",null,CardMgnt.PERSONALALL,{isCreate:true})
		CardMgnt.cardUser.show("bindinfodiv",null,CardMgnt.PERSONALALL)
	}

	//读卡
	function onReadCard(){
		try{
			var data = CardMgnt.onFindCard("readCardForm","mgntQueryService.getCardUserInfo",null,true);
			if (!CardMgnt.checkInUseCard(data.card)) return;
			if (!data.cardType.anonymous) {showWarning("该卡不是不记名卡，不能做不记名卡升级！");onCancel();return;}
			
			pageData.cardPin = data.cardPin;
			pageData.cardUser = data.cardUser;
			
			CardMgnt.cardUser.showData("bindinfodiv",data,CardMgnt.PERSONALALL);
			$("updateCardbtn").disabled = false;
			var fee = CardMgnt.getFee(Constants.ACCOUNT_FEE_UPGRAD_ANON_CARD,data.cardType.id);
			readCardForm.feeText.value = Format.fenToYuan(fee);
		}catch(e){showError(e.description);}
	}
	
	function selCardType(){
		if (!pageData.cardUser){showWarning("未读不记名卡，不能选择卡片类型！");return;}
		CardStore.selCardType(function(ct){
				var userLevel = ct[7]
				if (userLevel > pageData.cardUser.currentLevel){showError("所选择的卡片类型使用等级高于客户当前等级，不能升级！");return;}
				readCardForm.cardType.value = ct[0];
				readCardForm.cardTypeName.value = ct[1];
			},{defBaseCardType:BaseCardType.PERSONAL,anonymous:false,userLevel : pageData.cardUser.currentLevel})
	}
	function updateAnonCard(){
		var asn = readCardForm.asn.value;
		if (!checkForm(readCardForm)) return;
		if (!checkForm(CardMgnt.customer.formName)) return;
		if (!checkForm(CardMgnt.cardUser.formName)) return;
		if (!CardMgnt.checkCardAsn(asn)) return;

		if (!showQuestion("是否升级不记名卡？")) return;
		
		var cardTypeId = readCardForm.cardType.value;
		var customer = CardMgnt.customer.get();
		if (!customer.checkIdno){
			var c = DWR.syncCall("customerService.getCustomerForCardUser",customer.idno,customer.idnoType);
			if (c){
				if (!showQuestion("档案已经存在，是否升级为该档案下的客户？")){onCancel();return;}
				customer.id = c.id
			}
		}
		var cardUser = CardMgnt.cardUser.get();
		
		var usePin = cardUser.usePin == "true";
		cardUser.usePin = getNeedPin();
		
		DWR.call("cardMgntService.updateAnonCard",asn,cardTypeId,customer,cardUser,function(data){
			showInformation("不记名卡升级成功！");
			switchPage("detview");
			CardMgnt.showPrintView("detview","anon_update_bill",data.logId,"不记名卡升级凭证");
			
			try{WebPrint.print('billview');}catch(e){showWarning("打印出错："+e.description);return;}
			
			while(true){
				try{
					CardMgnt.syncCardData(asn,pageData.cardPin);
					break;
				}catch(e){
					if (showQuestion("同步卡数据失败！是否重试？<br>错误："+e.description)) continue;
					
					if(showQuestion("同步卡数据失败！是否换卡？")){
						CardMgnt.badCard.gotoPage(asn,CardMgnt.badCard.UPGRAD);
					}
					return;
				}
			}
			
			try{
				if (cardUser.usePin != usePin)
					CardMgnt.usePinApp(asn,usePin,pageData.cardPin);
			}catch(e){
				showError(e.description);return;
			}
		});
	}
	
	function onCancel(){
		switchPage("readcardview");
		CardMgnt.customer.show("customerdiv",null,CardMgnt.PERSONALALL,{isCreate:true})
		CardMgnt.cardUser.show("bindinfodiv",null,CardMgnt.PERSONALALL)
		pageData = {}
		readCardForm.reset();
		$("updateCardbtn").disabled = true;
	}
		</script>
</head>
<body onload="load()">
<div class="nav">
<div id="nav">&nbsp;</div>
</div>

<div id="readcardview">
<div id="readcarddiv">
	<form id="readCardForm" name="readCardForm">
		<input type="hidden" name="cardType">
		<div class="form">
			<div class="formTitle">卡片信息</div>
			<table cellSpacing="0" cellPadding="4" width="100%" border="0" class="col2 label6">
				<tr>
					<td><label>卡 号</label> <input type="text" name="asn" readonly class="readonly"></td>
					<td><label>卡类型</label> <input type="text" name="subCardTypeText" readonly class="readonly"></td>
				</tr>
				<tr>
					<td><label>新卡类型</label> <input type="text" name="cardTypeName" readonly class="readonly" onblur="checkV(this,'',true)"><a class="orga" href="#" onclick="selCardType();return false;">&nbsp;&nbsp;</a><span class="des">*</span></td>
					<td><label>手续费</label> <input type="text" name="feeText" readonly class="readonly"></td>
				</tr>
			</table>
		</div>
	</form>
</div>
<div id="customerdiv" class="form"></div>
<div id="bindinfodiv" class="form"></div>
<p>
<button id="readCardBtn" onclick="onReadCard()">读 卡</button>
<button id="updateCardbtn" onclick="updateAnonCard()" disabled>升
级</button>
<button onclick="onCancel()">重 置</button>
</p>
</div>
<!--明细(新增)静态页面部分-->
<div id="detview" style="display: none;">
</div>
</body>
</html>